import React, { Component } from 'react';
import ReactDom from 'react-dom'

let strong = `<strong>saber</strong>`;

class Clock extends Component {
    state = {
        time: new Date().toLocaleString()
    }
    componentDidMount() {
        this.timer = setInterval(() => {
            this.setState({ time: new Date().toLocaleString() })
        }, 1000);
    }
    render() {
        return (
            <>
                <div className='saber' style={{ color: "red" }}>
                    当前时间是：{this.state.time}
                </div>
                <div dangerouslySetInnerHTML={{ __html: strong }}></div>
                <button onClick = {() => {
                    alert(1)
                }}>click me</button>
            </>
        )
    }
    componentWillUnmount() {
        clearInterval(this.timer)
    }
}

ReactDom.render(<Clock></Clock>, document.getElementById('root'))